#include "NavigationLibrary.h"


extern "C" {
	 void CreateNavigation() {
		if (navigation != nullptr)
		{
			delete(navigation);
			navigation = nullptr;
		}

		navigation = new Navigation();
	}
	 void ReleaseNavigation()
	{
		if (navigation != nullptr)
		{
			delete(navigation);
			navigation = nullptr;
		}
	}

	  void LoadTile( char* path) {
		if (navigation == nullptr) return;
		navigation->LoadTile(path);
	}
	  bool LoadTileFromBuffer( unsigned char* data, size_t size)
	  {
		  if (navigation == nullptr) return false;
		 return navigation->LoadTileFromBuffer(data,size);
	  }

	 dtStatus FindRandomPointAroundCircle(NavPoint centerPos,  float radius, NavPoint* outPos) {
		if (navigation == nullptr) return DT_FAILURE;
		return navigation->FindRandomPointAroundCircle(centerPos, radius, outPos);
	}

	 dtStatus FindNearestPoly( float* startPos, NavPoint* navPoint,  float *polyPickExt) {
		if (navigation == nullptr) return DT_FAILURE;
		return navigation->FindNearestPoly(startPos, navPoint, polyPickExt);
	}

	 dtStatus FindNearestPolyNoPickExt( float* startPos, NavPoint* navPoint) {
		if (navigation == nullptr) return DT_FAILURE;
		return navigation->FindNearestPoly(startPos, navPoint);
	}

	 dtStatus FindPathStraight( float* startPos,  float* endPos, float *out_list, int* count) {
		if (navigation == nullptr) return DT_FAILURE;
		return navigation->FindPathStraight(startPos, endPos, out_list, count);
	}

	 dtStatus FindRaycast( float* startPos,  float* endPos, float* out_hitPos, float* out_tangent)
	 {
		 if (navigation == nullptr) return DT_FAILURE;
		 return navigation->FindRaycast(startPos, endPos, out_hitPos, out_tangent);
	 }
	 bool DtStatusSucceed(dtStatus status)
	 {
		 return dtStatusSucceed(status);
	 }

	 bool LoadTempObstacleTile(const char* path) 
	 {
		 if (navigation == nullptr) return false;
		 return navigation->LoadTempObstacleTile(path);
	 }
	 bool LoadTempObstacleTileFromBuffer(unsigned char* data, size_t size)
	 {
		 if (navigation == nullptr) return false;
		 return navigation->LoadTempObstacleTileFromBuffer(data,size);
	 }

	 dtStatus AddBoxObstacle(const float* bmin, const float* bmax, dtObstacleRef* result)
	 {
		 if (navigation == nullptr) return DT_FAILURE;
		 return navigation->AddBoxObstacle(bmin, bmax, result);
	 }
	 // Box obstacle: can be rotated in Y.
	 dtStatus AddBoxObstacleBox(const float* center, const float* halfExtents, const float yRadians, dtObstacleRef* result) 
	 {
		 if (navigation == nullptr) return DT_FAILURE;
		 return navigation->AddBoxObstacle(center, halfExtents, yRadians, result);
	 }
	 // Cylinder obstacle.
	 dtStatus AddObstacle(const float* pos, const float radius, const float height, dtObstacleRef* result)
	 {
		 if (navigation == nullptr) return DT_FAILURE;
		 return navigation->AddObstacle(pos, radius, height, result);
	 }
	 dtStatus RemoveObstacle(const dtObstacleRef ref)
	 {
		 if (navigation == nullptr) return DT_FAILURE;
		 return navigation->RemoveObstacle(ref);
	 }
}
